/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.common.constant.project;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * 系统级别
 * @author zpy
 * @version 1.0.0
 */
public enum SecurityLevel {
    /**
     * 未定级
     */
    DEFAULT(0,"未定级"),
    /**
     * 二级
     */
    TWO(2,"二"),
    /**
     * 三级
     */
    THREE(3,"三"),
    /**
     * 四级
     */
    FOUR(4,"四");

    private final int level;
    private final String name;

    SecurityLevel(int level, String name) {
        this.level = level;
        this.name = name;
    }

    public static SecurityLevel fromLevel(Integer level){
        SecurityLevel data = DEFAULT;
        for(SecurityLevel tt :SecurityLevel.values()){
            if(tt.level == level){
                data = tt;
                break;
            }
        }
        return data;
    }

    public static SecurityLevel fromName(String name){
        SecurityLevel data = DEFAULT;
        for(SecurityLevel tt :SecurityLevel.values()){
            if(StringUtils.equals(tt.getName(),name)){
                data = tt;
                break;
            }
        }
        return data;
    }

    public static List<SecurityLevel> getSupportLevels(){
        return Arrays.asList(TWO,THREE,FOUR);
    }

    public int getLevel(){
        return this.level;
    }

    public String getName(){
        return this.name;
    }
}